package com.aforce.models;

import javax.media.j3d.Appearance;
import javax.media.j3d.ColoringAttributes;
import javax.media.j3d.Material;
import javax.media.j3d.QuadArray;
import javax.media.j3d.Shape3D;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;



public class Box extends Shape3D
{

	public Box(double xsize, double ysize, double zsize)
	{
		super();
		double xmin = -xsize / 2.0;
		double xmax = xsize / 2.0;
		double ymin = -ysize / 2.0;
		double ymax = ysize / 2.0;
		double zmin = -zsize / 2.0;
		double zmax = zsize / 2.0;

		QuadArray box = new QuadArray(24, QuadArray.COORDINATES | QuadArray.NORMALS);

		Point3d verts[] = new Point3d[24];

		// front face
		verts[0] = new Point3d(xmax, ymin, zmax);
		verts[1] = new Point3d(xmax, ymax, zmax);
		verts[2] = new Point3d(xmin, ymax, zmax);
		verts[3] = new Point3d(xmin, ymin, zmax);
		// back face
		verts[4] = new Point3d(xmin, ymin, zmin);
		verts[5] = new Point3d(xmin, ymax, zmin);
		verts[6] = new Point3d(xmax, ymax, zmin);
		verts[7] = new Point3d(xmax, ymin, zmin);
		// right face
		verts[8] = new Point3d(xmax, ymin, zmin);
		verts[9] = new Point3d(xmax, ymax, zmin);
		verts[10] = new Point3d(xmax, ymax, zmax);
		verts[11] = new Point3d(xmax, ymin, zmax);
		// left face
		verts[12] = new Point3d(xmin, ymin, zmax);
		verts[13] = new Point3d(xmin, ymax, zmax);
		verts[14] = new Point3d(xmin, ymax, zmin);
		verts[15] = new Point3d(xmin, ymin, zmin);
		// top face
		verts[16] = new Point3d(xmax, ymax, zmax);
		verts[17] = new Point3d(xmax, ymax, zmin);
		verts[18] = new Point3d(xmin, ymax, zmin);
		verts[19] = new Point3d(xmin, ymax, zmax);
		// bottom face
		verts[20] = new Point3d(xmin, ymin, zmax);
		verts[21] = new Point3d(xmin, ymin, zmin);
		verts[22] = new Point3d(xmax, ymin, zmin);
		verts[23] = new Point3d(xmax, ymin, zmax);

		box.setCoordinates(0, verts);
		setGeometry(box);
		


		   final float[] normals = {
		   // Front Face
		      0.0f,  0.0f,  1.0f,     0.0f,  0.0f,  1.0f,
		      0.0f,  0.0f,  1.0f,     0.0f,  0.0f,  1.0f,
		   // Back Face
		      0.0f,  0.0f, -1.0f,     0.0f,  0.0f, -1.0f,
		      0.0f,  0.0f, -1.0f,     0.0f,  0.0f, -1.0f,
		   // Right Face
		      1.0f,  0.0f,  0.0f,     1.0f,  0.0f,  0.0f,
		      1.0f,  0.0f,  0.0f,     1.0f,  0.0f,  0.0f,
		   // Left Face
		     -1.0f,  0.0f,  0.0f,    -1.0f,  0.0f,  0.0f,
		     -1.0f,  0.0f,  0.0f,    -1.0f,  0.0f,  0.0f,
		   // Top Face
		      0.0f,  1.0f,  0.0f,     0.0f,  1.0f,  0.0f,
		      0.0f,  1.0f,  0.0f,     0.0f,  1.0f,  0.0f,
		   // Bottom Face
		      0.0f, -1.0f,  0.0f,     0.0f, -1.0f,  0.0f,
		      0.0f, -1.0f,  0.0f,     0.0f, -1.0f,  0.0f,
		   };

		
		   QuadArray quadArray = new QuadArray(24, QuadArray.COORDINATES | 
	                  QuadArray.NORMALS |
	                  QuadArray.TEXTURE_COORDINATE_2);
			quadArray.setCoordinates(0, verts);
			quadArray.setNormals(0, normals);
			
			quadArray.setCoordinates(0, verts);
			quadArray.setNormals(0, normals);
		setGeometry(quadArray);
		
		
		/*

		Appearance app = new Appearance();
		Material m = new Material(new Color3f(0.6f, 0.3f, 0.0f), new Color3f(0.6f, 0.3f, 0.0f), new Color3f(0.6f, 0.3f, 0.0f), new Color3f(0.6f, 0.3f, 0.0f), 100.0f);
		ColoringAttributes ca = new ColoringAttributes();
		ca.setColor(0.6f, 0.3f, 0.0f);
		app.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);
		app.setColoringAttributes(ca);
		m.setLightingEnable(true);
		app.setMaterial(m);
		
		setAppearance(app);
		setAppearance(new Appearance());
		*/
	}
}

